<!DOCTYPE html>
<!-- saved from url=(0049)https://v3.bootcss.com/examples/starter-template/ -->
<html lang="zh-CN">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" href="https://v3.bootcss.com/favicon.ico">
    <title>云打印平台</title>
    <script src="/js/jquery.min.js"></script>
    <script src="/js/art-template.js"></script>
    <script src="/js/art-template-ex.js"></script>
    <script src="/js/signalr.min.js"></script>
    <!-- Bootstrap core CSS -->
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/p.css" rel="stylesheet">
</head>


<body style="background-color: rgb(238,240,244);">
    <nav class="navbar navbar-inverse navbar-fixed-top no-print">
        <div class="title">云打印平台</div>
        <div class="title print-btn">
            <button type="button" class="btn btn-primary" onclick="javascript:window.print();" autocomplete="off">
                打印
            </button>
        </div>
        <div class="title back-btn">
            <button type="button" class="btn btn-primary" onclick="javascript:window.location.reload();"
                autocomplete="off">
                退出
            </button>
        </div>
    </nav>
    <div class="container" style="padding: 0px;">
        <iframe id="template-container" data-ref="iframeEl" frameBorder="0"></iframe>
        <div id="countdown"></div>

        <div class="code-container no-print">
            <img class="code" id="qrcode" />
        </div>
        <script>
            let intervalId = null;
            let codeId = null;
            let countdown = 10;
            const ws = new signalR.HubConnectionBuilder()
                .withUrl("http://nmcx.wx.smgxh.com/wsprint")
                .withAutomaticReconnect()
                .build();

            ws.start().then(function () {
                console.log("connected");
            });

            ws.on("ReceiveMessage", (message) => {
                var res = JSON.parse(message);
                switch (res && res.Data && res.Data.Method) {
                    case 'GetId':
                        showQrcode(res);
                        break;
                    case 'GetStatus':
                        showStatus(res);
                        break;
                    case 'GetContent':
                        showContent(res);
                        break;

                }
            });
            function showQrcode(res) {
                if (res.Success === true) {
                    const templateContainer = document.querySelector('#qrcode');
                    templateContainer.setAttribute('src', "data:image/jpeg;base64," + res.Data.Url.replace(' ', '+'));
                }
            }

            function showStatus(res) {
                if (res.Success === true) {
                    switch (res.Data.Data) {
                        case 1:  //等待扫码
                            console.log('等待扫码');
                            getContent();
                            break;
                        case 2:  //已扫码
                            console.log('已扫码');
                            break;
                        case 3:  //已确认
                            clearInterval(intervalId);
                            getContent();
                            break;
                        case 4:  //成功
                            break;
                        case 5:  //失败
                            break;
                        case 6:  //确认超时
                            break;
                    }
                }
            }

            function showContent(res) {
                // if (res.Success === true) {
                const data = '{"campusId":"18031313215260100003","campusName":"绵竹校区","nation":1,"birthday":"1998-11-30 00:00:00","isBind":false,"testStatus":6,"enrollStatus":4,"isPaid":true,"name":"李璐桧","sex":2,"idcard":"511111199811302923","schemeName":"天一学院2018(9)-单招","areaName":"四川省乐山市沙湾区","school":"四川省乐山沫若中学","testNum":"18511003120176","eduStatus":3,"politics":13,"examineeType":4,"examineeSubjectType":2,"testType":1,"isAdjust":true,"majorId1":"18022716273438800577","majorId2":"18022716273438800577","majorId3":"18022716273438800577","major1LearnLevel":2,"major2LearnLevel":2,"major3LearnLevel":2,"majorName1":"护理","majorName2":"护理","majorName3":"护理","remark":"","money":0.0,"sort":0,"teacherName":"汤悦 ","linkMan":"李璐桧2","address":"四川省乐山市沙湾区福禄镇燕子坎村6组7号2","postCode":"614902","phone":"15828549702","customerId":"18031713220574802108","enrollId":"18031713220574902112","headImg":"","nickName":"","codeUrl":"201/18022710341615600002/code/511111199811302923_CODE_128.jpg","imgUrl":"201/18022710341615600002/head/18511003120176.jpg","isOnlyChild":false,"bloodType":0,"healthStatus":0,"weight":0.00,"stature":0.00,"firstCompleteFee":"2018-05-07 00:00:00","shouldMoney":43350.00,"paidMoney":29280.00,"zbShouldMoney":0.0,"zbPaidMoney":0.0,"studentStatusId":"18042714275867809531","financeNum":"201181801","dataScore":"40%","currentMajor":"护理","currentLearnLevel":2,"createCharge":0,"zbCount":0,"zhuanFANote":"","changeEms":true,"changeEmsStatus":2,"schoolStatus":0,"interYear":0,"interMonth":0,"interItem":0,"interLearnLevel":0,"id":"18031713220574902112","creatorId":"18022709341460200019","creatorName":"administrator","created":"2018-03-17 13:22:45","modifierId":"taskServiceUserId","modifierName":"taskServiceUserName","modified":"2019-12-09 16:10:37","state":0}';
                const tpl = JSON.parse(localStorage.getItem('ax-data-template'));
                if (tpl && tpl['test_admissionticket']) {
                    const html = template.render(tpl['test_admissionticket'], JSON.parse(data));
                    const templateContainer = document.querySelector('#template-container');
                    templateContainer.setAttribute('srcDoc', html);
                    // setTimeout(function () { window.print(); }, 50);
                    // print(html);
                }
                // }
            }

            function showCountdown() {
                intervalId = setInterval(function () {
                    const cd = document.querySelector('#countdown');
                    cd.innerHTML = countdown;
                    countdown--
                    if (countdown < 0) { clearInterval(intervalId); location.reload(); }
                }, 1000);
            } 
        </script>
    </div>

    <footer class="footer no-print">
        <div class="container">
            <p class="text-muted">Copyright ©2020 四川希望教育产业集团.</p>
        </div>
    </footer>

</body>

</html>